package com.source.lightfowl.person.service.impl;

import com.source.lightfowl.person.dao.PersonDao;
import com.source.lightfowl.person.dao.RoleDao;
import com.source.lightfowl.person.entity.Role;
import com.source.lightfowl.person.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDao roleDao;

    @Autowired
    private PersonDao personDao;

    @Override
    public void addRole(Role role) {
        roleDao.save(role);
    }

    @Override
    public void deleteRole(String rid) {
        personDao.deleteRoleNull(rid);
        roleDao.deleteByRid(rid);
    }

    @Override
    public List<Role> querryRole(String rname) {
        return roleDao.findByRnameLike("%"+rname+"%");
    }

    @Override
    public List<Role> querryRoleAll() {
        return roleDao.findAll();
    }

    @Override
    public Role querryUserPower(String role) {
        return roleDao.findByRid(role);
    }

    @Override
    public void updateRole(Role role){
        roleDao.updateRolename(role.getRid(), role.getRname());
    }

    public String findRid(String name) {
        return roleDao.findRidByname(name);
    }
}
